package com.itheima.threadstructuredemo;

import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

public class TreadMain {

    public static void main(String[] args) throws InterruptedException {
        // 创建一个List集合，用于存储红包
        List<Integer> redPackets = getRedPackets(100);
        List<Employee> employees = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            // 创建一个Employee对象，用于存储红包
            Employee employee = new Employee("员工" + (i + 1), 0);
            employees.add(employee);
            // 创建一个ThreadGetRedPacket对象，用于获取红包
            Runnable threadGetRedPacket = new ThreadGetRedPacket(employee);
            // 创建一个Thread对象，用于执行获取红包的线程
            Thread t = new Thread(threadGetRedPacket);
            // 启动线程
            t.start();
        }
        ThreadGetRedPacket.redPackets = redPackets;
        Thread.sleep(2000);

        Collections.sort(employees, (o1, o2) -> o2.getGetRedPacketNum() - o1.getGetRedPacketNum());
        for (int i = 0; i < employees.size(); i++) {
            System.out.println(employees.get(i));
        }


    }

    // 准备num个随机的红包，其中价值为1到30的整数的红包数占30%，31到100的占70%
    public static List<Integer> getRedPackets(int num) {
        // 创建一个List集合，用于存储红包
        List<Integer> redPackets = new ArrayList<>();
        // 创建一个Random对象，用于生成随机数
        Random random = new Random();
        for (int i = 0; i < num * 0.3; i++){
            redPackets.add(random.nextInt(30) + 1);
        }
        for (int i = 0; i < num * 0.7; i++){
            redPackets.add(random.nextInt(70) + 31);
        }
        // 打乱红包
        Collections.shuffle(redPackets);
        return redPackets;
    }


}
